import os, sys

from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template import RequestContext

from damn import TranscoderInstance, ProviderInstance, AnalyzerInstance

def index(request):
  allplugins = {}
  for type, m in {'Transcoders':TranscoderInstance, 'Analyzers':AnalyzerInstance, 'Providers':ProviderInstance}.items():
    manager = m()
    allplugins[type] = []
    for plugin_info in manager.getAllPlugins():
      plugin_info.success = True
      plugin_info.exception = None
      allplugins[type] .append(plugin_info)
    for a, z, plugin_info, exception in manager._failed_candidates:
      plugin_info.success = False
      plugin_info.exception = exception
      allplugins[type] .append(plugin_info)
  return render_to_response('plugins.html', {'allplugins': allplugins}, context_instance=RequestContext(request))
